package chd.edu.train.business.controller.admin;

import chd.edu.train.business.req.DailyTrainCarriageQueryReq;
import chd.edu.train.business.req.DailyTrainCarriageSaveReq;
import chd.edu.train.business.resp.DailyTrainCarriageQueryResp;
import chd.edu.train.business.service.DailyTrainCarriageService;
import chd.edu.train.common.resp.CommonResp;
import chd.edu.train.common.resp.PageResp;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

/**
 * @author Zhang Chaoliang
 * create 2023
 */
@RestController
@RequestMapping("/admin/daily-train-carriage")
public class DailyTrainCarriageAdminController {

    @Resource
    private DailyTrainCarriageService dailyTrainCarriageService;

    /**
     * 保存/修改编辑信息
     * @param req
     * @return
     */
    @PostMapping("/save")
    public CommonResp<Object> save(@Valid @RequestBody DailyTrainCarriageSaveReq req){
        dailyTrainCarriageService.save(req);

        return new CommonResp<>();
    }

    /**
     * 保存信息
     * @param req
     * @return
     */
    @GetMapping("/query-list")
    public CommonResp<PageResp<DailyTrainCarriageQueryResp>> queryList(@Valid DailyTrainCarriageQueryReq req){
        PageResp<DailyTrainCarriageQueryResp> list = dailyTrainCarriageService.queryList(req);

        return new CommonResp<>(list);
    }

    /**
     * 删除信息
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    public CommonResp<Object> delete(@PathVariable Long id){
        dailyTrainCarriageService.delete(id);

        return new CommonResp<>();
    }

}
